<template>
  <div class="app-container">
    <el-card>
      <div slot="header">
        <el-search-form label-width="90px" @search="onSearch" @reset="onReset">
          <el-form-item label="关键词">
            <el-input size="small" v-model="searchBody.keyword" class="el-input__small"></el-input>
          </el-form-item>
          <el-form-item label="操作时间">
            <el-date-picker
              size="small"
              v-model="searchBody.dateRange"
              type="datetimerange"
              start-placeholder="开始日期"
              end-placeholder="结束日期"
              :default-time="['00:00:00', '23:59:59']"
              value-format="yyyy-MM-dd HH:mm:ss"
            ></el-date-picker>
          </el-form-item>
        </el-search-form>
      </div>
      <div class="pagination-box__withButton">
        <div>
        </div>
        <el-pagination
          small
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          :current-page="pageNo"
          :page-sizes="pageSizeOpts"
          :page-size="pageSize"
          layout="total, sizes, prev, pager, next, jumper"
          :total="totalCount"
        ></el-pagination>
      </div>
      <div class="have-pagination-container">
        <el-table v-loading="loading.list" border :data="list">
          <el-table-column align="center" label="ID" prop="id" width="100"></el-table-column>
          <el-table-column width="100" label="系统名称" prop="systemName" align="center"></el-table-column>
          <el-table-column width="120" label="模块名称" prop="moduleName" align="center"></el-table-column>
          <el-table-column width="100" label="操作描述" prop="moduleValue" align="center"></el-table-column>
          <el-table-column width="150" label="方法名" prop="methodName" align="center"></el-table-column>
          <el-table-column label="请求参数" prop="params" align="center"></el-table-column>
          <el-table-column label="响应参数" prop="response" align="center"></el-table-column>
          <el-table-column width="120" label="IP地址" prop="ip" align="center"></el-table-column>
          <el-table-column width="100" label="执行时间（毫秒）" prop="time" align="center"></el-table-column>
          <el-table-column width="120" label="操作人" prop="createUser" align="center"></el-table-column>
          <el-table-column width="120" label="操作时间" prop="createDate" align="center"></el-table-column>
        </el-table>
      </div>
      <div class="pagination-box">
        <el-pagination
          small
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          :current-page="pageNo"
          :page-sizes="pageSizeOpts"
          :page-size="pageSize"
          layout="total, sizes, prev, pager, next, jumper"
          :total="totalCount"
        ></el-pagination>
      </div>
    </el-card>
  </div>
</template>

<script>
import { sysLog_list } from "@/api/platformSys";
const getDefaultSearchBody = () => ({
  keyword: null,
  dateRange: null
});
export default {
  data() {
    return {
      handleType: "",
      pageNo: 1,
      pageSize: 20,
      totalCount: 0,
      pageSizeOpts: [20, 50, 100, 300, 500],
      loading: {
        list: false
      },
      list: [],
      searchBody: getDefaultSearchBody()
    };
  },
  created() {
    this.getData();
  },
  methods: {
    getData() {
      const { dateRange, ...rest } = this.searchBody;
      const [startTime, endTime] = dateRange || [null, null];
      this.loading.list = true;
      sysLog_list({
        pageNo: this.pageNo,
        pageSize: this.pageSize,
        startTime,
        endTime,
        ...rest
      }).then(({ result }) => {
        this.list = result.data;
        this.totalCount = result.totalCount;
        this.loading.list = false;
      });
    },
    handleSizeChange(val) {
      this.pageSize = val;
      this.getData();
    },
    handleCurrentChange(val) {
      this.pageNo = val;
      this.getData();
    },
    onSearch() {
      this.pageNo = 1;
      this.getData();
    },
    onReset() {
      this.pageNo = 1;
      this.searchBody = getDefaultSearchBody();
      this.getData();
    },

    handleClick(type, row = {}) {
      this.handleType = type;
      switch (type) {
        case "add":
          this.updateForm = getDefaultForm();
          this.updateDialog = true;
          this.$nextTick(() => {
            this.$refs.updateForm.clearValidate();
          });
          break;
        default:
          return;
      }
    }
  }
};
</script>
